﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using System.Runtime.Serialization;
using PMisuseAn.behaviour.adaptation;

namespace PMisuseAn.io
{
    [Serializable()]
    public class ThreatAdaptationActionDescDB : ISerializable
    {
        public string clusterName;
        public AdaptationDescriptor ad;
        public string violatingPolicyStatement;
        public string threatMessageTransition;
        public string violatingContext;
        public string rationale;
        public int seqTimeline;
        
        //Default constructor
        public ThreatAdaptationActionDescDB(AdaptationDescriptor ad_,
            string violatingPolicyStatement_, string threatMessageTransition_, string violatingContext_, string rationale_, int seqTimeline_)
        {
            clusterName = MainWindow.clusterName;
            ad = ad_;
            violatingPolicyStatement = violatingPolicyStatement_;
            threatMessageTransition = threatMessageTransition_;
            violatingContext = violatingContext_;
            rationale = rationale_;
            seqTimeline = seqTimeline_;
        }

        //Deserialization constructor.
        public ThreatAdaptationActionDescDB(SerializationInfo info, StreamingContext ctxt)
        {
            //Get the values from info and assign them to the appropriate properties
            clusterName = (string)info.GetValue("projectClusterName", typeof(string));
            violatingPolicyStatement = (string)info.GetValue("violatingPolicyStatement", typeof(string));
            threatMessageTransition = (string)info.GetValue("threatMessageTransition", typeof(string));
            violatingContext = (string)info.GetValue("violatingContext", typeof(string));
            rationale = (string)info.GetValue("rationale", typeof(string));
            seqTimeline = (int)info.GetValue("seqTimeline", typeof(int));
            ad = (AdaptationDescriptor)info.GetValue("adaptationDescriptor", typeof(behaviour.adaptation.AdaptationDescriptor));
        }
        
        //Serialization function.
        public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
        {
            info.AddValue("projectClusterName", clusterName);
            info.AddValue("violatingPolicyStatement", violatingPolicyStatement);
            info.AddValue("threatMessageTransition", threatMessageTransition);
            info.AddValue("violatingContext", violatingContext);
            info.AddValue("rationale", rationale);
            info.AddValue("seqTimeline", seqTimeline);
            info.AddValue("adaptationDescriptor", ad);
        }

    }
}


